/**
 * 
 */
package de.cbf.cam.dsa.model.entities.weapon;

import java.beans.PropertyChangeSupport;

import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;

import de.cbf.cam.dsa.model.Activator;
import de.cbf.cam.dsa.model.entities.OneNPC;
import de.cbf.cam.dsa.model.entities.WeaponStyle;

/**
 * @author Nebelritter
 *
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class WeaponMelee extends OneWeapon {
	public static final int TYPE_Offense 	= 1<<1;
	public static final int TYPE_Parry 		= 1<<2;
	public static final int TYPE_Shield 	= 1<<3;
	public static final int TYPE_Unarmed 	= 1<<4;
	
	public static final float PIKE 			= 3;
	public static final float STANGENWAFFE 	= 2;
	public static final float NAHKAMPF 		= 1;
	public static final float HANDGEMENGE 	= 0.5f;
	
	public static final int DKH =1<<0; 
	public static final int DKN =1<<1;
	public static final int DKS =1<<2;
	public static final int DKP =1<<3;
	
	/**
	 * @uml.property  name="kkStep"
	 */
	private int kkStep;
	/**
	 * @uml.property  name="kkTreshold"
	 */
	private int kkTreshold;
	
	/**
	 * @uml.property  name="length"
	 */
	private int length;
	
	/**
	 * @uml.property  name="bf"
	 */
	private int bf;
	
	/**
	 * @uml.property  name="iniMod"
	 */
	private int iniMod;
	
	/**
	 * @uml.property  name="wmAT"
	 */
	private int wmAT;
	/**
	 * @uml.property  name="wmPA"
	 */
	private int wmPA;
	
	/**
	 * @uml.property  name="dkBits"
	 */
	private int dkBits;
	
	public static final String PROPERTYNAME ="WeaponMelee";
	/**
	 * @uml.property  name="propertyChangeSupport"
	 */
	public PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
	/**
	 * @param style
	 */
	public WeaponMelee() {
		super();		
	}
	
	@Override
	public WeaponInUse useIt(OneNPC character,String styleTalentToUse) {		
		WeaponStyle style = null;
		for(int i = 0;i < styles.size(); i++){
			if(styles.get(i).getTalentName().equals(styleTalentToUse)){
				style = styles.get(i);
				break;
			}
		}
		if(style==null){
			Activator.logger.error("Chosen styleTalent "+styleTalentToUse+" for useIt not present on weapon "+this);
		}
		WeaponMeleeInUse weaponInUse = new WeaponMeleeInUse(this, style); 
		return weaponInUse;
	}
	@Transient
	public Float getMaxRange(){
		if((getDkBits()&WeaponMelee.DKP)==WeaponMelee.DKP){
			return WeaponMelee.PIKE;
		}
		if((getDkBits()&WeaponMelee.DKS)==WeaponMelee.DKS){
			return WeaponMelee.STANGENWAFFE;
		}
		if((getDkBits()&WeaponMelee.DKN)==WeaponMelee.DKN){
			return WeaponMelee.NAHKAMPF;
		}		
		if((getDkBits()&WeaponMelee.DKH)==WeaponMelee.DKH){
			return WeaponMelee.HANDGEMENGE;
		}
		Activator.logger.error("Max Range of weapon could not be found\n" +
				"DkBits are:"+dkBits);
		return 0F;
	}
	
	/**
	 * @return  the bf
	 * @uml.property  name="bf"
	 */
	public int getBf() {
		return bf;
	}
	/**
	 * @param bf  the bf to set
	 * @uml.property  name="bf"
	 */
	public void setBf(int bf) {
		this.bf = bf;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"bf",null,bf);
	}
	/**
	 * @return  the iniMod
	 * @uml.property  name="iniMod"
	 */
	public int getIniMod() {
		return iniMod;
	}
	/**
	 * @param iniMod  the iniMod to set
	 * @uml.property  name="iniMod"
	 */
	public void setIniMod(int iniMod) {
		this.iniMod = iniMod;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"iniMod",null,iniMod);
	}
	/**
	 * @return the kkStep
	 */
	public int getKKStep() {
		return kkStep;
	}
	/**
	 * @param kkStep the kkStep to set
	 */
	public void setKKStep(int step) {
		this.kkStep = step;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"tpKKTP",null,step);
	}
	/**
	 * @return the kkTreshold
	 */
	public int getKKTreshold() {
		return kkTreshold;
	}
	/**
	 * @param kkTreshold the kkTreshold to set
	 */
	public void setKKTreshold(int treshold) {
		this.kkTreshold = treshold;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"tpKKKK",null,treshold);
	}

	/**
	 * @return the length
	 */
	public int getWeapLength() {
		return length;
	}
	/**
	 * @param length the length to set
	 */
	public void setWeapLength(int length) {
		this.length = length;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"length",null,length);
	}
	/**
	 * @return  the wmAT
	 * @uml.property  name="wmAT"
	 */
	public int getWmAT() {
		return wmAT;
	}
	/**
	 * @param wmAT  the wmAT to set
	 * @uml.property  name="wmAT"
	 */
	public void setWmAT(int wmAT) {
		this.wmAT = wmAT;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"wmAT",null,wmAT);
	}
	/**
	 * @return  the wmPA
	 * @uml.property  name="wmPA"
	 */
	public int getWmPA() {
		return wmPA;
	}
	/**
	 * @param wmPA  the wmPA to set
	 * @uml.property  name="wmPA"
	 */
	public void setWmPA(int wmPA) {
		this.wmPA = wmPA;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"wmPA",null,wmPA);
	}
	/**
	 * @return  the dkBits
	 * @uml.property  name="dkBits"
	 */
	public int getDkBits() {
		return dkBits;
	}
	/**
	 * @param dkBits  the dkBits to set
	 * @uml.property  name="dkBits"
	 */
	public void setDkBits(int dkBits) {
		this.dkBits = dkBits;
		propertyChangeSupport.firePropertyChange(PROPERTYNAME+"dkBits",null,dkBits);
	}
	/**
	 * @return
	 * @uml.property  name="length"
	 */
	public int getLength() {
		return length;
	}
	/**
	 * @param length
	 * @uml.property  name="length"
	 */
	public void setLength(int length) {
		this.length = length;
	}
	

	
}
